//
//  TabBarController.m
//  FreshMember
//
//  Created by qyc on 2019/4/8.
//  Copyright © 2019年 qyc. All rights reserved.
//

#import "TabBarController.h"
#import "NavigationController.h"
#import "HAHomeViewController.h"
#import "HAUserViewController.h"
#import "WebNoNavViewController.h"

@interface TabBarController ()

@end

@implementation TabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tabBar.translucent = NO;
    
    // 添加所有子制器
    [self setUpAllChildViewController];
    
    // Do any additional setup after loading the view.
}

/**
 *  添加所有子制器
 */
-(void)setUpAllChildViewController{
    
    // 1.添加第一个控制器
    HAHomeViewController *oneVC = [[HAHomeViewController alloc]init];
    [self addOneChildVc:oneVC title:@"首页" imageName:@"tab_1" selectedImageName:@"tab_01"];
}

/**
 *  添加一个子控制器的方法
 */
- (void)addOneChildVc:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName
{
    // 设置TabBarItem的普通文字颜色
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:UIColorFromRGB(0xA9A9A9), NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    // 设置TabBarItem的选中文字颜色
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:COLOR_MAIN, NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
    // 设置图标
    childVc.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 设置标题
    childVc.title = title;
    // 添加tabBar控制器的子控制器
    NavigationController *nav = [[NavigationController alloc]initWithRootViewController:childVc];
    [self addChildViewController:nav];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
